package com.test.dao;

import com.test.pojo.User;
import com.test.util.MyBatisUtils;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;


public class UserTest1 {
    static Logger logger = Logger.getLogger(UserTest1.class);
    @Test
    public void test4(){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        // 通过 RowBounds 实现分页
        RowBounds rowBounds = new RowBounds(1, 2);
        //UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = sqlSession.selectList("com.test.dao.UserMapper.getUserRowBounds",null,rowBounds);
        for (User user : userList) {
            System.out.println(user);
        }
        sqlSession.close();
    }

    @Test
    public void test3(){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        HashMap<String, Integer> map = new HashMap<String,Integer>();
        map.put("startIndex",0);
        map.put("pageSize",2);
        List<User> userList = mapper.getUserByLimit(map);
        System.out.println(userList);
        sqlSession.close();
    }


    @Test
    public void test1(){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = mapper.getUserList();
        System.out.println(userList);
        sqlSession.close();
    }
    @Test
    public void test2(){
        logger.info("info:进入了log4j方法");
        logger.debug("debug:进入了log4j方法");
        logger.error("error:进入了log4j方法");
    }
}
